#include "PCH.h"
#include "AppLoop.h"

namespace DeviousRenderer
{
AppLoop gAppLoop;

int AppPreInit(const TCHAR* command)
{
	return 1;
}

int AppInit(const TCHAR* command)
{
	return gAppLoop.Init();
}

void AppLooping()
{
	gAppLoop.Loop();
}

void AppExit()
{
	gAppLoop.Exit();
}

bool IsRequestingExit()
{
	return gAppLoop.IsRequestingExit();
}

int GuardedMain( const WCHAR* CmdLine, HINSTANCE hInInstance, HINSTANCE hPrevInstance, int nCmdShow )
{
	int ErrorLevel = AppPreInit( CmdLine );

	ErrorLevel = AppInit(CmdLine);
	// exit if PreInit failed.
	if ( ErrorLevel == 0)
		return ErrorLevel;

	AppLooping();
	AppExit();

	return ErrorLevel;
}

}

#ifdef WIN32
int WINAPI WinMain( HINSTANCE hInInstance, HINSTANCE hPrevInstance, char*, int nCmdShow )
{
	try
	{
		const WCHAR* CmdLine = GetCommandLine();
		DeviousRenderer::GuardedMain(CmdLine, hInInstance, hPrevInstance, nCmdShow);
	}
	catch (...)
	{
	}

	return 0;
}

#endif